﻿#pragma once

#include "Framework/Application.h"
#include "Output/Console.h"

#include "TestObject.h"

#include "Deprecated/Buffer.h"

#include "Serialize/JsonSerializer.h"


int main(int argc, char* argv[])
{
    auto App=NewObject<RApplication>();
    
    SApplicationArgument Argument;
    Argument.ExecutablePath=SPath(argv[0]);

    App->Initialize(Argument);


    auto Test=NewObject<RTestObject>();
    Test->s=3;
    Test->Bool=true;
    Test->Float=4.666f;
    Test->Double=5.21;
    Test->str=U"asdasdqqqqqq";
    Test->IntArray= {2,31,1111,666};
    Test->ID=SGuid::NewGuid();
    Test->TestPath=SPath(U"D:/2344.json");
    Test->SubclassOfObject=RTestObject::StaticClass();
    STestStruct sssss;
    sssss.sss=2123;
    Test->TestStructMap.Add(22,sssss);
    Test->TestStructMap.Add(221,sssss);
    Test->TestStruct.sss=123123;
    Test->TestDelegate.BindScript(Test,&RTestObject::TestFunction);

    auto Json=CJsonSerializer().SerializeToJson(Test);
    
    WH::PrintLine(U"Serialized Json :");
    CString Result;
    Result=CJsonUtils::ToString(Json);
    WH::PrintLine(Result);


    auto Test2=NewObject<RTestObject>();
    CJsonDeserializer().DeserializeFromJson(Test2,Json);

    Test2->TestDelegate.Broadcast();

    CString Result2;
    auto Json2=CJsonSerializer().SerializeToJson(Test2);
    Result2=CJsonUtils::ToString(Json2);
    WH::PrintLine(U"Serialized twice Json :");
    WH::PrintLine(Result2);


    STestStruct TestStruct;
    TestStruct.sss=111;
    // TestStruct.Buffer.Data->Add(1);
    // TestStruct.Buffer.Data->Add(218);
    WH::PrintLine(U"Serialize  struct Json :");
    auto StructJson=CJsonSerializer().SerializeToJson(&TestStruct,TestStruct.GetStruct());
    CString StructResult=CJsonUtils::ToString(StructJson);
    WH::PrintLine(StructResult);


    STestStruct TestStruct2;
    CJsonDeserializer().DeserializeFromJson(&TestStruct2,TestStruct2.GetStruct(),StructJson);
    auto StructJson2=CJsonSerializer().SerializeToJson(&TestStruct,TestStruct.GetStruct());
    WH::PrintLine(U"Serialize struct twice Json :");
    CString StructResult2=CJsonUtils::ToString(StructJson2);
    WH::PrintLine(StructResult2);

    // {
    //     WH::Cout()<<"Test SBuffer"<<WH::EndL();
    //     SBuffer Buffer;

    //     Buffer.Data->Add(1);
    //     Buffer.Data->Add(18);
    //     Buffer.Data->Add(200);

    //     CString BufferString=Buffer.ToString();

    //     SBuffer Buffer2;
    //     Buffer2.FromString(BufferString);

    //     for(auto & Data: Buffer2.Data)
    //     {
    //         WH::Cout()<<(int)Data<<WH::EndL();
    //     }

    // }
}